package goleetcode

func temperatureTrend(temperatureA []int, temperatureB []int) int {
	trendA, trendB := make([]int, len(temperatureA)), make([]int, len(temperatureB))
	trendA[0] = SMOOTH
	trendB[0] = SMOOTH
	for i := 1; i < len(temperatureA); i++ {
		tmp := temperatureA[i] - temperatureA[i-1]
		if tmp > 0 {
			trendA[i] = UP
		} else if tmp == 0 {
			trendA[i] = SMOOTH
		} else {
			trendA[i] = DOWN
		}
	}
	for i := 1; i < len(temperatureB); i++ {
		tmp := temperatureB[i] - temperatureB[i-1]
		if tmp > 0 {
			trendB[i] = UP
		} else if tmp == 0 {
			trendB[i] = SMOOTH
		} else {
			trendB[i] = DOWN
		}
	}
	ans := 0
	cur := 0
	for i := 1; i < len(trendA); i++ {
		if trendA[i] == trendB[i] {
			cur++
			ans = max(ans, cur)
		} else {
			cur = 0
		}
	}
	return ans
}

const (
	UP = iota
	DOWN
	SMOOTH
)

